<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
		$this->display();
    }
	public function menu(){
		$jsonmenu = '{
			"button":[
				{
					"name":"服务",
					"sub_button":[
					{
						"name":"报障",
						"type":"view",
						"url":"http://www.mehuli.tk/index.php/home/index/index"
					},
					{
						"name":"领取任务",
						"type":"click",
						"key":"hahahahahahah"
					}
					],
				}
			]
		}';
				$token = A("Token");
		$access_token = $token->index();
		$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=$access_token";
		
		
		$result = $this->https_request($url, $jsonmenu);
		var_dump($result);
	}
	public function https_request($url, $data=null){
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
		if(!empty($data)){
			curl_setopt($curl, CURLOPT_POST, 1);
			curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
		}
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($curl);
		curl_close($curl);
		return $output;
	}
}